package com.example.administrator.yuejian2.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

import com.example.administrator.yuejian2.R;

public class RecyclerAdapter extends RecyclerView.Adapter{

    private Context context;
    public RecyclerAdapter (Context context)
    {
        this.context=context;
    }
    @Override
    public MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.logo_item,parent,false);
        MyViewHolder viewHolder =new MyViewHolder(view);//实例化viewholder
        return viewHolder;
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
        MyViewHolder viewHolder=(MyViewHolder)holder;
        viewHolder.textView.setText("Test"+position);
        viewHolder.imageView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Toast.makeText(context,"点击MyFragment",Toast.LENGTH_SHORT).show();
            }
        });
    }

    @Override
    public int getItemCount() {
        return 15;          //返回个每页的数量
    }
    static class MyViewHolder extends RecyclerView.ViewHolder
    {
        private TextView textView;
        private ImageView   imageView;
        public MyViewHolder(View itemview)
        {
            super(itemview);
            textView= (TextView) itemview.findViewById(R.id.content);
            imageView= (ImageView) itemview.findViewById(R.id.image);

        }
    }
}
